package cn.com.bluemoon.daps.system.controller.api;


import cn.com.bluemoon.daps.api.sys.RemoteSysConfigService;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants;
import cn.com.bluemoon.daps.common.datascope.IgnorePermission;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.system.entity.DapSystemConfigSandbox;
import cn.com.bluemoon.daps.system.service.DapSystemConfigSandboxService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 沙箱环境、ptOsc等等基本配置
 * </p>
 *
 * @author admin
 * @since 2021-06-25
 */
@Api(tags = {"FeignClient服务-沙箱环境配置"})
@RequestMapping(ServiceNameConstants.DapsApiSystem.API_CONFIG)
@RestController
@Slf4j
@IgnorePermission(name = "服务注册-沙箱环境配置")
public class DapSystemConfigApi implements RemoteSysConfigService {
    @Resource
    private DapSystemConfigSandboxService sandboxService;

    @GetMapping("")
    @ApiOperation("获取系统配置-最新的一个沙箱环境")
    public ResultBean<DapSystemConfigSandbox> sandboxConfig() {
        @SuppressWarnings("unchecked") LambdaQueryWrapper<DapSystemConfigSandbox> eq = sandboxService.bmLambdaQuery().orderByDesc(DapSystemConfigSandbox::getId, DapSystemConfigSandbox::getCreateTime).last("limit 1");
        DapSystemConfigSandbox sandbox = sandboxService.getOne(eq);
        return sandbox == null ? ResultBean.error("系统未配置沙箱环境信息") : ResultBean.ok(sandbox);
    }
}
